/**
 * create by young (young2f@outlook.com) on 2020/9/16
 */


'use strict';
import React from 'react';
import {Button, Form, Input, notification} from 'antd';

import {FormField, FormLayout, ModalFooter} from 'antd-extra';
import FormBase from '../../../components/Base/FormBase';
import {connect} from "dva";
import moment from 'moment';
import 'moment/locale/zh-cn';

moment.locale('zh-cn');
const table = 'Customer';
@Form.create()
@connect(({user, global, dynamicLabel, customer}) => ({...user, ...customer, ...dynamicLabel, ...global}))
export default class ModalCreateOrEditContact extends FormBase {
  constructor(props) {
    super(props);
    this.state = {};
  }

  renderFoot = () => {
    const {foot, value, modalRef, callback, form} = this.props;

    if (foot) {
      return foot(value, modalRef);
    } else {
      return (
        <ModalFooter>
          <Button type="primary" onClick={() => {
            form.validateFields((err, values) => {
              if (err) {
                const {code} = err;
                const {errors} = code;
                errors.forEach(item => {
                  notification.error(item);
                });
                return;
              }
              _.merge(values, this.state);
              callback(values);
              modalRef.close();
            });
          }}>确定</Button>
          <Button onClick={() => {
            modalRef.close();
          }}>取消</Button>
        </ModalFooter>
      );
    }
  };


  render() {
    const {form, style, values = {}, cols = 2} = this.props;
    const {contacts, address, contactsPhone, position, memo} = values;
    this.state.code = values.code ? values.code : new Date().valueOf();
    return (
      <div style={{...style}}>
        {<FormLayout form={form} cols={cols}>
          <FormField
            label={'联系人'}
            name={'contacts'}
            initialValue={contacts}
            required={true}
          >
            <Input style={{width: '100%'}}
            ></Input></FormField>
          <FormField
            label={'联系地址'}
            name={'address'}
            initialValue={address}

          >
            <Input style={{width: '100%'}}
            ></Input></FormField>
          <FormField
            label={'联系电话'}
            name={'contactsPhone'}
            required={true}
            initialValue={contactsPhone}

          >
            <Input style={{width: '100%'}}
            ></Input></FormField>
          <FormField
            label={'职务'}
            name={'position'}
            initialValue={position}
          >
            <Input style={{width: '100%'}}
            ></Input></FormField>
          <FormField
            label={'备注'}
            name={'memo'}
            initialValue={memo}
          >
            <Input.TextArea style={{width: '100%'}}
            ></Input.TextArea>
          </FormField>
        </FormLayout>}
        {this.renderFoot()}
      </div>

    );
  }
}

